<?php
namespace app\admin\controller;

use \think\Controller;
use \think\captcha\Captcha;
use \app\admin\model\Login;
use \think\Session;
class Index extends Controller
{
    public function index()
    {
       if(request()->isPost()){
    		$ca=input('J_codetext');
    		if(!captcha_check($ca)){
 			//验证失败
    			$this->error("验证码错误！");
			}
			//判断账号密码
			else{
				$a=input('adminname');
				$b=input('password');
				
				$log = new Login;
				$result=$log->login($a,$b);
				if($result==1){
					$this->error("用户不存在!");
				}else if($result==2){
					$this->error("密码错误！");
				}else{
					$this->redirect("user/index");
				}

			}
    		
    	}

    	return $this->fetch();
    }
     public function show_captcha(){
		ob_clean();
		$captcha = new Captcha();
		$captcha->fontSize =14;
		$captcha->length   = 3;
		$captcha->useNoise = false;
		return $captcha->entry();
	}
	public function logout(){
		Session::clear();
		$this->redirect('index/index');
	}
}
